/*
 * LevelPanelController.cpp
 *
 *  Created on: 05/11/2012
 *      Author: san
 */

#include "LevelView.h"
#include <iostream>
LevelView::LevelView(){
	this->Gtk::Fixed::show();
	this->backgroundEvent.add(this->backgroundImage);
	this->add(this->backgroundEvent);
	this->backgroundEvent.show();
	this->backgroundEvent.set_visible_window(false);
}

LevelView::~LevelView() {
	this->clearScreen();
}

void LevelView::setBackground(std::string path) {
	this->backgroundImage.set(path);
	this->backgroundImage.show();
}

void LevelView::show(std::vector<VisibleElement *> elements) {
	this->clearScreen();
	Drop *drop;
	std::vector<VisibleElement *>::iterator it = elements.begin();
	while (it != elements.end()) {
		drop = new Drop(*it);
		this->dropList.push_back(drop);
		this->put(*drop, drop->getX(), drop->getY());
		++it;
	}
}

void LevelView::clearScreen() {
	std::list<Drop *>::iterator i;
	for(i = this->dropList.begin() ; i != this->dropList.end() ; ++i) {
		this->remove(*(*i));
		delete *i;
	}
	this->dropList.clear();
}

Glib::SignalProxy1< bool,GdkEventButton* > LevelView::signal_button_press_event() {
	return this->backgroundEvent.signal_button_press_event();
}

std::list<Drop *> &LevelView::getDrops() {
	return this->dropList;
}
